% update ethnic group
function new = UpdateGroup(old, n)
cnt = 1;
% 依次排，相同的会排在一起，那么这样顺次交叉不会有问题吗？测试发现两者没有区别
% for j = 1 : size(n)
%     if n(j) ~= 0
%         j1 = n(j);
%         while(j1 > 0)
%             new(cnt,:) = old(j,:);
%             cnt = cnt + 1;
%             j1 = j1 - 1;
%         end
%     end
% end

% 新族群，高适应度乱序版
rows = size(n,1);
new = [];
while sum(n) ~= 0
    if(n(cnt,1) > 0)
        new = [new;old(cnt,:)];
        n(cnt,1) = n(cnt,1) - 1;   
    end
    cnt = cnt + 1;
    if(cnt > rows)
        cnt = 1;
    end
end
